﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SeaBattle.Domain.Abstract.Services;
using SeaBattle.Domain.Entities;
using SeaBattle.Domain.Abstract;

namespace SeaBattle.Domain.Concrete.Services
{
    public class FakeGameService : IGameService
    {
        private IPlayerService playerService;
        private static IList<Game> games = new List<Game>();

        private IGameRepository gameRepository;


        public FakeGameService(IPlayerService playerService, IGameRepository gameRepository)
        {
            this.playerService = playerService;
            this.gameRepository = gameRepository;
            //InitializeGames();
        }

        //private void InitializeGames()
        //{
        //    if (games.Count == 0)
        //    {
        //        games.Add(new Game(1, DateTime.Now, playerService.GetPlayer("vasya")) { Preset = 100, Opened = true });
        //        games.Add(new Game(2, DateTime.Now, playerService.GetPlayer("vasya")) { Preset = 200, Opened = false });
        //        games.Add(new Game(3, DateTime.Now, playerService.GetPlayer("andrew")) { Preset = 300, Opened = true });
        //        games.Add(new Game(4, DateTime.Now, playerService.GetPlayer("vasya")) { Preset = 400, Opened = true });
        //    }
        //}

        public IEnumerable<Game> GetOpenedGames()
        {
            return games
                .Where(x => x.Opened)
                .OrderBy(x => x.Preset);
        }


        //public Game GetGameById(int gameId)
        //{
        //    return games.First(x => x.Id == gameId);
        //}


        public IEnumerable<Game> GetParticipantsPlayerGames(Player player)
        {
            return games
                .Where(x => (x.Creator == player || x.Opponent == player))
                .OrderByDescending(x => x.Created);
        }
    }
}
